package net.crowdloud.server.DatabaseAccess.solution;

import javax.jdo.PersistenceManager;

import net.crowdloud.client.solution.SolutionDatabaseServerCalls;
import net.crowdloud.server.DatabaseAccess.DatabaseConnection;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * 
 * @Architecture
 */
@SuppressWarnings("serial")
public class SolutionDatabaseImplementation extends RemoteServiceServlet
		implements SolutionDatabaseServerCalls {

	@Override
	public void addSolution(Long userID,
			net.crowdloud.shared.entities.Solution solution, String tags) {

		PersistenceManager persistenceManager = DatabaseConnection.connect();

		SaveSolution.addNew(persistenceManager, userID, solution, tags);

		persistenceManager.close();
	}

	@Override
	public void updateSolution(Long userID,
			net.crowdloud.shared.entities.Solution solution, String tags) {

		if (solution.getSolutionID() == null) {

			addSolution(userID, solution, tags);

		} else {

			PersistenceManager persistenceManager = DatabaseConnection
					.connect();

			SaveSolution.update(persistenceManager, solution, tags);

			persistenceManager.close();
		}
	}
}
